package cn.cdeden.knowledge.domain;

//import cn.cdeden.knowledge.domain.vo.PersonalFilesTreeVo;
import cn.cdeden.common.core.utils.MapstructUtils;
import cn.cdeden.knowledge.api.domain.vo.RemotePersonalTreeVo;
import cn.cdeden.knowledge.domain.dto.FilesTree;
import cn.cdeden.knowledge.domain.dto.PersonalToEnterpriseDto;
import cn.cdeden.knowledge.domain.vo.FilesTreeRecycleVo;
import cn.cdeden.knowledge.domain.vo.PersonalFilesTreeVo;
import cn.cdeden.knowledge.enums.TreeTypeEnum;
import cn.cdeden.resource.api.domain.RemoteEsFilesTree;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.Date;

import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMappers;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

/**
 * 个人文档树
 */
@Data
//@Builder
@NoArgsConstructor
@TableName(value = "personal_files_tree")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@AutoMappers({@AutoMapper(target = PersonalFilesTreeVo.class),
    @AutoMapper(target = FilesTree.class),
    @AutoMapper(target = PersonalFilesTree.class),
    @AutoMapper(target = FilesTreeRecycleVo.class),
    @AutoMapper(target = FilesTreeRecycle.class),
    @AutoMapper(target = TreeDownloadFiles.class),
    @AutoMapper(target = RemotePersonalTreeVo.class),
    @AutoMapper(target = RemoteEsFilesTree.class),
    @AutoMapper(target = PersonalToEnterpriseDto.class)})
//@AutoMapper(target = PersonalFilesTreeVo.class, reverseConvertGenerate = false)
public class PersonalFilesTree implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 编号
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 排序字段
     */
    @TableField(value = "sort")
    private Integer sort;

    /**
     * 树的头节点
     */
    @TableField(value = "top_parent_id")
    private String topParentId;

    /**
     * 父亲编号
     */
    @TableField(value = "parent_id")
    private String parentId;

    /**
     * 上级的id
     */
    @TableField(value = "superiors_ids")
    private String superiorsIds;

    /**
     * 后缀名
     */
    @TableField(value = "suffix")
    private String suffix;

    /**
     * 名称
     */
    @TableField(value = "real_name")
    private String realName;

    /**
     * 上级路径
     */
    @TableField(value = "superiors_path")
    private String superiorsPath;

    /**
     * 路径
     */
    @TableField(value = "`path`")
    private String path;

    /**
     * 类型
     */
    @TableField(value = "`type`")
    private String type;

    /**
     * 储存表id
     */
    @TableField(value = "storage_id")
    private String storageId;

    /**
     * 储存服务器类型
     */
    @TableField(value = "storage_type")
    private String storageType;

    /**
     * 文件大小
     */
    @TableField(value = "`size`")
    private Long size;

    /**
     * 版本
     */
    @TableField(value = "edition_name")
    private String editionName;

    /**
     * 版本号
     */
    @TableField(value = "edition")
    private String edition;

    /**
     * 文件的MD5
     */
    @TableField(value = "file_md5")
    private String fileMd5;

    /**
     * 关连状态
     */
    @TableField(value = "linking_state")
    private String linkingState;

    /**
     * 创建编号
     */
    @TableField(value = "create_id")
    private String createId;

    /**
     * 创建者
     */
    @TableField(value = "create_by")
    private String createBy;

    /**
     * 创建日期
     */
    @TableField(value = "create_time")
    private Date createTime;

    /**
     * 更新编号
     */
    @TableField(value = "update_id")
    private String updateId;

    /**
     * 更新者
     */
    @TableField(value = "update_by")
    private String updateBy;

    /**
     * 更新时间
     */
    @TableField(value = "update_time")
    private Date updateTime;

    /**
     * 删除编号
     */
    @TableField(value = "delete_id")
    private String deleteId;

    /**
     * 删除者
     */
    @TableField(value = "delete_by")
    private String deleteBy;

    /**
     * 删除时间
     */
    @TableField(value = "delete_time")
    private Date deleteTime;

    /**
     * 删除 是否可以被查询
     */
    @TableField(value = "delete_type")
    private String deleteType;

    /**
     * 备注
     */
    @TableField(value = "remarks")
    private String remarks;

    /**
     * 系统
     */
    @TableField(value = "sys")
    private String sys;

    /**
     * 文档内容
     */
    @TableField(value = "doc_content")
    private String docContent;


    @TableField(exist = false)
    private String collection;

    @TableField(value = "es_id")
    private String esId;

    @TableField(value = "expert")
    private String expert;

    @TableField(value = "file_dataset_id")
    private String fileDatasetId;

    public PersonalFilesTree(String createId, String createBy) {
        this.createId = createId;
        this.createBy = createBy;
        this.createTime = new Date();
        this.updateId = createId;
        this.updateBy = createBy;
        this.updateTime = new Date();


    }


    public PersonalFilesTree filesCopy(String createId, String createBy) {
        PersonalFilesTree tree = MapstructUtils.convert(this, PersonalFilesTree.class);
//        PersonalFilesTree tree = ConvertUtil.convert(this, PersonalFilesTree.class);
        tree.setId(null);
        tree.setCreateId(createId);
        tree.setCreateBy(createBy);
        tree.setCreateTime( new Date());
        tree.setUpdateId(null);
        tree.setUpdateBy(null);
        tree.setUpdateTime(null);
        tree.setUpdateTime(null);
        if(StringUtils.equalsIgnoreCase(tree.getType(), TreeTypeEnum.FOLDER.getType())){
            tree.setSize(null);
        }


        return tree ;
    }
}
